#!/bin/bash
#description: install csvn${VER} on centos7.3
#需要以普通用户csvn运行该脚本
SOFTDIR=/opt/tools
VER=5.1.5
user=csvn
group=csvn
DIR=/opt/data 
[ ! -d $SOFTDIR ] && sudo mkdir $SOFTDIR
#安装jdk环境
cd $SOFTDIR && [ ! -f jdk-8u111-linux-x64.tar.gz   ] && sudo wget http://soft.51yuki.cn/jdk-8u111-linux-x64.tar.gz  && sudo tar xf jdk-8u111-linux-x64.tar.gz -C /usr/local/
cd /usr/local
sudo ln -s /usr/local/jdk1.8.0_111  /usr/local/jdk
#安装collabnet subversion
cd $SOFTDIR && [ ! -f CollabNetSubversionEdge-${VER}_linux-x86_64.tar.gz ] && sudo wget http://soft.51yuki.cn/CollabNetSubversionEdge-${VER}_linux-x86_64.tar.gz
[ ! -d $DIR ] && sudo mkdir $DIR
sudo tar xf CollabNetSubversionEdge-${VER}_linux-x86_64.tar.gz -C /opt/data
#把/opt/data/csvn的属主和属组改成csvn
sudo chown -R $user.$group ${DIR}/csvn
#更改path环境变量
echo "export JAVA_HOME=/usr/local/jdk" >> /home/csvn/.bash_profile
echo "export PATH=${JAVA_HOME}/bin:$PATH" >> /home/csvn/.bash_profile
echo "export PATH=${DIR}/csvn/bin:$PATH">> /home/csvn/.bash_profile
source /home/csvn/.bash_profile
#修改csvn.conf
cd ${DIR}/csvn/data/conf 
sudo cp csvn.conf.dist csvn.conf
sudo sed -i "s@JAVA_HOME=@JAVA_HOME=/usr/local/jdk@g" csvn.conf
sudo sed -i "s/#RUN_AS_USER=/RUN_AS_USER=$user/g" csvn.conf
sudo sed -i "s/JAVA_REQUIRED_VERSION=1.6/JAVA_REQUIRED_VERSION=1.8/g" csvn.conf
#安装csvn
cd ${DIR}/csvn/bin && sudo ./csvn install
#以csvn用户启动csvn服务
${DIR}/csvn/bin/csvn start
#配置防火墙
sudo setenforce 0 #临时关闭selinux
sudo firewall-cmd --add-port=3343/tcp
sudo firewall-cmd --add-port=3343/tcp --permanent
sudo firewall-cmd --reload

